#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File    :   whois_api.py    
@Contact :   291622538@qq.com

@Modify Time      @Author    @Version    @Description
------------      -------    --------    -----------
2021/3/31 19:27   fan        1.0         None
"""

# 获取顶级域名对应的api
import json

# 获取顶级域名对应的api
import tldextract


def get_services_dict(file_name):
    with open(file_name, 'r') as load_f:
        load_dict = json.load(load_f)
    services_dict = {}
    for service in load_dict["services"]:
        for suffix in service[0]:
            services_dict[suffix] = "".join(service[1])
    return services_dict


# 解析域名
def extract():
    domain = "facebook.com"
    val = tldextract.extract(domain)
    # val.suffix 表示顶级域名
    domain_name = val.domain + "." + val.suffix
    print(domain_name)


if __name__ == '__main__':
    get_services_dict("data/dns.json")
    extract()
